package com.example.redisspringdemo.demos;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    //
    @GetMapping("/testString")
    public String testString(){
        redisTemplate.opsForValue().set("key","111");
        redisTemplate.opsForValue().set("key2","222");
        redisTemplate.opsForValue().set("key3","333");

        String value = redisTemplate.opsForValue().get("key");
        System.out.println(value);

        return "ok";
    }
    @GetMapping("testList")
    public String testList(){
        redisTemplate.execute((RedisConnection redisConnection)->{
            redisConnection.flushAll();
            return null;
        });
//
        redisTemplate.opsForList().leftPush("key","111");
        redisTemplate.opsForList().leftPush("key","222");
        redisTemplate.opsForList().leftPush("key","333");

        String value = redisTemplate.opsForList().rightPop("key");
        System.out.println(value);
        value = redisTemplate.opsForList().rightPop("key");
        System.out.println(value);
        value = redisTemplate.opsForList().rightPop("key");
        System.out.println(value);
        return "ok";
    }
}
